<?php
namespace App\Repositories\Common;

use App\Models\Model;
use App\Repositories\BaseRepository;
use App\Models\Common\Area;
use App\Exceptions\OrdinaryException;

class MapRepository extends BaseRepository {

    public function model()
    {
        // TODO: Implement model() method.
        return Area::class;
    }

    /**
     * 根据父级id获取子集列表
     *
     * @author zx
     * @date 2019-01-21
     * @param int $pid 父级ID
     * @return Model
     */
    public function getPCA(int $pid=0)
    {
        $lists = $this->where("upid", $pid)->get();
        if($lists->isNotEmpty()) return $lists;
        throw new OrdinaryException("未找到数据");
    }

    /**
     * 获取地址名称
     *
     * @author zx
     * @date 2019-01-22
     * @param array $idArr id集合
     * @return string
     */
    public function getAddressName(array $ids):string
    {
        $list = $this->whereIn("id", $ids)->get(['name']);
        $str = '';
        foreach ($list as $key => $val) {
            $str .= $val->name.' ';
        }
        return rtrim($str, ' ');
    }

    public function serialization(array $attributes)
    {
        // TODO: Implement serialization() method.
    }

}